package com.ruoyi.community.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.community.mapper.CpcActivityEnrollMapper;
import com.ruoyi.community.mapper.CpcActivityParticipateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.community.mapper.CpcActivityMapper;
import com.ruoyi.community.domain.CpcActivity;
import com.ruoyi.community.service.ICpcActivityService;

/**
 * 党建活动Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-12-22
 */
@Service
public class CpcActivityServiceImpl implements ICpcActivityService 
{
    @Autowired
    private CpcActivityMapper cpcActivityMapper;
    
    @Autowired
    private CpcActivityEnrollMapper cpcActivityEnrollMapper;
    
    @Autowired
    private CpcActivityParticipateMapper cpcActivityParticipateMapper;

    /**
     * 查询党建活动
     * 
     * @param activityId 党建活动ID
     * @return 党建活动
     */
    @Override
    public CpcActivity selectCpcActivityById(String activityId)
    {
        CpcActivity resultCpcActivity = cpcActivityMapper.selectCpcActivityById(activityId);
        Long viewNumber = resultCpcActivity.getViewNumber() + 1;
        resultCpcActivity.setViewNumber(viewNumber);
        updateCpcActivity(resultCpcActivity);
//        return cpcActivityMapper.selectCpcActivityById(activityId);
        return resultCpcActivity;
    }

    /**
     * 查询党建活动列表
     * 
     * @param cpcActivity 党建活动
     * @return 党建活动
     */
    @Override
    public List<CpcActivity> selectCpcActivityList(CpcActivity cpcActivity)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        cpcActivity.setCommunityId(Long.valueOf(loginUser.getCommunityId()));
        return cpcActivityMapper.selectCpcActivityList(cpcActivity);
    }

    /**
     * 新增党建活动
     * 
     * @param cpcActivity 党建活动
     * @return 结果
     */
    @Override
    public int insertCpcActivity(CpcActivity cpcActivity)
    {
        cpcActivity.setCreater(SecurityUtils.getUsername());
        cpcActivity.setCommunityId(Long.valueOf(SecurityUtils.getCommunityId()));
        Long registerCode = Math.round((Math.random()+1) * 1000);
        cpcActivity.setRegisterCode(registerCode);
        return cpcActivityMapper.insertCpcActivity(cpcActivity);
    }

    /**
     * 修改党建活动
     * 
     * @param cpcActivity 党建活动
     * @return 结果
     */
    @Override
    public int updateCpcActivity(CpcActivity cpcActivity)
    {
        return cpcActivityMapper.updateCpcActivity(cpcActivity);
    }

    /**
     * 批量删除党建活动
     * 
     * @param activityIds 需要删除的党建活动ID
     * @return 结果
     */
    @Override
    public int deleteCpcActivityByIds(String[] activityIds)
    {
        return cpcActivityMapper.deleteCpcActivityByIds(activityIds);
    }

    /**
     * 删除党建活动信息
     * 
     * @param activityId 党建活动ID
     * @return 结果
     */
    @Override
    public int deleteCpcActivityById(String activityId)
    {
        return cpcActivityMapper.deleteCpcActivityById(activityId);
    }
}
